Skip to content

build: eliminate precompiled headers from bazel build.#799

Closed
htuch wants to merge 1 commit intoenvoyproxy:masterfrom
htuch:precompiled-remove-pr
Closed

build: eliminate precompiled headers from bazel build.#799
htuch wants to merge 1 commit intoenvoyproxy:masterfrom
htuch:precompiled-remove-pr

Conversation

@htuch
Copy link
Member

@htuch htuch commented Apr 20, 2017

Since Bazel doesn't support precompiled headers (bazelbuild/bazel#1215),
we actually suffer a slowdown rather than speedup by having all files implicitly include
precompiled.h in the Bazel build. I found ~10% performance improvement on my workstation, going from
181s to 163s for a "bazel build //test/..." from a "bazel clean" state.

This patch makes all includes now explicit. This will slowdown the cmake build, but since this is
not long for this world it seems alright. The header reordering in this patch was achieved using #793.
The addition of the missing headers in each file was done using a modified version of the tool in #793,
which substituted in headers based on simple substring matches (e.g. whenever it saw std::string in
a file, it added #include ). Here's the patterns I ended up using that seemed to work:

sys_extra_includes = [
('std::runtime_error', 'stdexcept'),
('strcmp', 'string.h'),
('strcasecmp', 'strings.h'),
('std::unique_ptr', 'memory'),
('std::shared_ptr', 'memory'),
('std::unordered_set', 'unordered_set'),
('std::transform', 'algorithm'),
('std::vector', 'vector'),
('std::regex', 'regex'),
('spdlog::', 'spdlog/spdlog.h'),
('fmt::format', 'spdlog/spdlog.h'),
('std::string', 'string'),
('uint32_t', 'cstdint'),
('uint64_t', 'cstdint'),
('std::array', 'array'),
('sockaddr_un', 'sys/un.h'),
('sockaddr_in', 'netinet/ip.h'),
('std::chrono', 'chrono'),
('std::list', 'list'),
('std::multimap', 'map'),
('std::unordered_map', 'unordered_map'),
('std::stringstream', 'sstream'),
('std::condition_variable', 'condition_variable'),
('std::mutex', 'mutex'),
(' ::close', 'unistd.h'),
('inet_ntop', 'arpa/inet.h'),
('inet_pton', 'arpa/inet.h'),
('htonl', 'arpa/inet.h'),
('setsockopt', 'sys/types.h'),
('setsockopt', 'sys/socket.h'),
('TCP_NODELAY', 'netinet/tcp.h'),
('SIGTERM', 'signal.h'),
('SIGPIPE', 'signal.h'),
('std::function', 'functional'),
('std::ifstream', 'fstream'),
('std::ofstream', 'fstream'),
('std::forward_list', 'forward_list'),
('std::atomic', 'atomic'),
('std::cerr', 'iostream'),
('hostent', 'netdb.h'),
(' bind(', 'sys/types.h'),
(' bind(', 'sys/socket.h'),
('std::ostream', 'iostream'),
]

extra_includes = [
('MOCK_METHOD', 'gmock/gmock.h'),
('MOCK_CONST_METHOD', 'gmock/gmock.h'),
('MATCHER_P', 'gmock/gmock.h'),
('ON_CALL', 'gmock/gmock.h'),
('using testing::', 'gmock/gmock.h'),
('testing::Test', 'gtest/gtest.h'),
('EXPECT
', 'gtest/gtest.h'),
('\nTEST(', 'gtest/gtest.h'),
('\nTEST_F(', 'gtest/gtest.h'),
('\nTEST_P(', 'gtest/gtest.h'),
('HeaderMapImpl', 'test/test_common/printers.h'),
('Buffer::', 'test/test_common/printers.h'),
('RespValue', 'test/test_common/printers.h'),
]

@mattklein123
Copy link
Member

looks good but obviously needs master merged now

Since Bazel doesn't support precompiled headers (bazelbuild/bazel#1215),
we actually suffer a slowdown rather than speedup by having all files implicitly include
precompiled.h in the Bazel build. I found ~10% performance improvement on my workstation, going from
181s to 163s for a "bazel build //test/..." from a "bazel clean" state.

This patch makes all includes now explicit. This will slowdown the cmake build, but since this is
not long for this world it seems alright. The header reordering in this patch was achieved using envoyproxy#793.
The addition of the missing headers in each file was done using a modified version of the tool in envoyproxy#793,
which substituted in headers based on simple substring matches (e.g. whenever it saw std::string in
a file, it added #include <string>). Here's the patterns I ended up using that seemed to work:

  sys_extra_includes = [
      ('std::runtime_error', 'stdexcept'),
      ('strcmp', 'string.h'),
      ('strcasecmp', 'strings.h'),
      ('std::unique_ptr', 'memory'),
      ('std::shared_ptr', 'memory'),
      ('std::unordered_set', 'unordered_set'),
      ('std::transform', 'algorithm'),
      ('std::vector', 'vector'),
      ('std::regex', 'regex'),
      ('spdlog::', 'spdlog/spdlog.h'),
      ('fmt::format', 'spdlog/spdlog.h'),
      ('std::string', 'string'),
      ('uint32_t', 'cstdint'),
      ('uint64_t', 'cstdint'),
      ('std::array', 'array'),
      ('sockaddr_un', 'sys/un.h'),
      ('sockaddr_in', 'netinet/ip.h'),
      ('std::chrono', 'chrono'),
      ('std::list', 'list'),
      ('std::multimap', 'map'),
      ('std::unordered_map', 'unordered_map'),
      ('std::stringstream', 'sstream'),
      ('std::condition_variable', 'condition_variable'),
      ('std::mutex', 'mutex'),
      (' ::close', 'unistd.h'),
      ('inet_ntop', 'arpa/inet.h'),
      ('inet_pton', 'arpa/inet.h'),
      ('htonl', 'arpa/inet.h'),
      ('setsockopt', 'sys/types.h'),
      ('setsockopt', 'sys/socket.h'),
      ('TCP_NODELAY', 'netinet/tcp.h'),
      ('SIGTERM', 'signal.h'),
      ('SIGPIPE', 'signal.h'),
      ('std::function', 'functional'),
      ('std::ifstream', 'fstream'),
      ('std::ofstream', 'fstream'),
      ('std::forward_list', 'forward_list'),
      ('std::atomic', 'atomic'),
      ('std::cerr', 'iostream'),
      ('hostent', 'netdb.h'),
      (' bind(', 'sys/types.h'),
      (' bind(', 'sys/socket.h'),
      ('std::ostream', 'iostream'),
  ]

  extra_includes = [
      ('MOCK_METHOD', 'gmock/gmock.h'),
      ('MOCK_CONST_METHOD', 'gmock/gmock.h'),
      ('MATCHER_P', 'gmock/gmock.h'),
      ('ON_CALL', 'gmock/gmock.h'),
      ('using testing::_', 'gmock/gmock.h'),
      ('testing::Test', 'gtest/gtest.h'),
      ('EXPECT_', 'gtest/gtest.h'),
      ('\nTEST(', 'gtest/gtest.h'),
      ('\nTEST_F(', 'gtest/gtest.h'),
      ('\nTEST_P(', 'gtest/gtest.h'),
      ('HeaderMapImpl', 'test/test_common/printers.h'),
      ('Buffer::', 'test/test_common/printers.h'),
      ('RespValue', 'test/test_common/printers.h'),
  ]
@htuch htuch force-pushed the precompiled-remove-pr branch from 12e840b to f02c5db Compare April 20, 2017 17:24
@mattklein123
Copy link
Member

Yay GH. This change is actually merged.

@mattklein123
Copy link
Member

Closing, I guess?

htuch added a commit to htuch/envoy that referenced this pull request Apr 20, 2017
Since Bazel doesn't support precompiled headers (bazelbuild/bazel#1215),
we actually suffer a slowdown rather than speedup by having all files implicitly include
precompiled.h in the Bazel build. I found ~10% performance improvement on my workstation, going from
181s to 163s for a "bazel build //test/..." from a "bazel clean" state.

This patch makes all includes now explicit. This will slowdown the cmake build, but since this is
not long for this world it seems alright. The header reordering in this patch was achieved using envoyproxy#793.
The addition of the missing headers in each file was done using a modified version of the tool in envoyproxy#793,
which substituted in headers based on simple substring matches (e.g. whenever it saw std::string in
a file, it added #include <string>). Here's the patterns I ended up using that seemed to work:

  sys_extra_includes = [
      ('std::runtime_error', 'stdexcept'),
      ('strcmp', 'string.h'),
      ('strcasecmp', 'strings.h'),
      ('std::unique_ptr', 'memory'),
      ('std::shared_ptr', 'memory'),
      ('std::unordered_set', 'unordered_set'),
      ('std::transform', 'algorithm'),
      ('std::vector', 'vector'),
      ('std::regex', 'regex'),
      ('spdlog::', 'spdlog/spdlog.h'),
      ('fmt::format', 'spdlog/spdlog.h'),
      ('std::string', 'string'),
      ('uint32_t', 'cstdint'),
      ('uint64_t', 'cstdint'),
      ('std::array', 'array'),
      ('sockaddr_un', 'sys/un.h'),
      ('sockaddr_in', 'netinet/ip.h'),
      ('std::chrono', 'chrono'),
      ('std::list', 'list'),
      ('std::multimap', 'map'),
      ('std::unordered_map', 'unordered_map'),
      ('std::stringstream', 'sstream'),
      ('std::condition_variable', 'condition_variable'),
      ('std::mutex', 'mutex'),
      (' ::close', 'unistd.h'),
      ('inet_ntop', 'arpa/inet.h'),
      ('inet_pton', 'arpa/inet.h'),
      ('htonl', 'arpa/inet.h'),
      ('setsockopt', 'sys/types.h'),
      ('setsockopt', 'sys/socket.h'),
      ('TCP_NODELAY', 'netinet/tcp.h'),
      ('SIGTERM', 'signal.h'),
      ('SIGPIPE', 'signal.h'),
      ('std::function', 'functional'),
      ('std::ifstream', 'fstream'),
      ('std::ofstream', 'fstream'),
      ('std::forward_list', 'forward_list'),
      ('std::atomic', 'atomic'),
      ('std::cerr', 'iostream'),
      ('hostent', 'netdb.h'),
      (' bind(', 'sys/types.h'),
      (' bind(', 'sys/socket.h'),
      ('std::ostream', 'iostream'),
  ]

  extra_includes = [
      ('MOCK_METHOD', 'gmock/gmock.h'),
      ('MOCK_CONST_METHOD', 'gmock/gmock.h'),
      ('MATCHER_P', 'gmock/gmock.h'),
      ('ON_CALL', 'gmock/gmock.h'),
      ('using testing::_', 'gmock/gmock.h'),
      ('testing::Test', 'gtest/gtest.h'),
      ('EXPECT_', 'gtest/gtest.h'),
      ('\nTEST(', 'gtest/gtest.h'),
      ('\nTEST_F(', 'gtest/gtest.h'),
      ('\nTEST_P(', 'gtest/gtest.h'),
      ('HeaderMapImpl', 'test/test_common/printers.h'),
      ('Buffer::', 'test/test_common/printers.h'),
      ('RespValue', 'test/test_common/printers.h'),
  ]
htuch added a commit to htuch/envoy that referenced this pull request Apr 20, 2017
jpsim pushed a commit that referenced this pull request Nov 28, 2022
These are never called in practice today. Since we don't want to support them in the initial version of filters, we're removing them from the public interfaces now.

Signed-off-by: Michael Rebello <me@michaelrebello.com>
Signed-off-by: JP Simard <jp@jpsim.com>
jpsim pushed a commit that referenced this pull request Nov 29, 2022
These are never called in practice today. Since we don't want to support them in the initial version of filters, we're removing them from the public interfaces now.

Signed-off-by: Michael Rebello <me@michaelrebello.com>
Signed-off-by: JP Simard <jp@jpsim.com>
mathetake added a commit that referenced this pull request Mar 3, 2026
**Description**
This commit uses "Install" func instead of AddToScheme(Deprecated).

---------

Signed-off-by: googs1025 <googs1025@gmail.com>
Co-authored-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants